﻿using Microsoft.ManagementConsole;
using Microsoft.ManagementConsole.Advanced;

namespace Vicos.Management
{
    /// <summary>
    /// SnapInSettings attribute - Used to set the registration information for the snap-in.
    /// SnapIn class - Provides the main entry point for the creation of a snap-in. 
    /// SimpleSnapIn class - Simplest class available. ex. Hello World  
    /// </summary>
    [SnapInSettings("{6FF0D8C8-E241-4EB0-B0BD-185448CB2A8A}",
        DisplayName = "ViCOS Admin",
        Description = "ViCOS Administration SnapIn",
        Vendor = "LMS Unicamp")
    ]
    [ExtendsNodeType("{1E5F3C57-CA68-4194-AE4B-45B4EA171E37}")] // extends the Features node
    public class ViCOSSnapIn : NamespaceExtension
    {
        // Clipboard 'id' of the machine name exposed by the snap-in
        private const string machineNameClipboardFormatId = "MMC_SNAPIN_MACHINE_NAME";

        // Store the extension's node
        private ScopeNode RootNode;

        // Sets up view to the shared data the extension is interested in
        public ViCOSSnapIn()
        {
            // In order to receive published data from the primary snap-in, MMC needs to know which
            // data items the extension is interested in. 
            // In this case, the primary snap-in publishes a data item called MMC_SNAPIN_MACHINE_NAME.
            PrimaryNode.SharedData.Add(new SharedDataItem(machineNameClipboardFormatId));
        }

        protected override void OnInitialize()
        {
            // create extension node
            this.RootNode = new ScopeNode();
            this.RootNode.DisplayName = "ViCOS Admin";
            this.RootNode.EnabledStandardVerbs = StandardVerbs.Refresh;
            PrimaryNode.Children.Add(RootNode);
    
            // Create a message view for the root node.
            MmcListViewDescription lvd = new MmcListViewDescription();
            lvd.DisplayName = "Failover Cluster Nodes (MmcListView)";
            lvd.ViewType = typeof(ManagementListView);
            //lvd.Options = MmcListViewOptions.;

            // Attach the view to the root node
            this.RootNode.ViewDescriptions.Add(lvd);
            this.RootNode.ViewDescriptions.DefaultIndex = 0;
        }
    }
}
